import sys
import pygame
import pygame
from pygame.locals import *
pygame.init()
#size = width, height = 501,448
screen = pygame.display.set_mode((501,448))#画布
background=pygame.image.load('.\\img\\bg.png')#导入图片
fum=pygame.image.load('.\\img\\fum.png').convert()
fum_rect=fum.get_rect()
# fum_surface=pygame.Surface((fum_rect.width,fum_rect.height))surface此处没有具体作用


screen.blit(fum, (10,10))

clock = pygame.time.Clock()#创建时钟对象
# #fum= pygame.transform.scale(fum,(45,45))#放缩图片大小
x=10#玩家x坐标,y坐标,移动速度v
y=10
v=12
start_x=0

while True:#死循环让窗口一直显示
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            sys.exit()
        # if event.type == pygame.KEYDOWN:  # 如果检测到按键按下
        #     if event.key == pygame.K_d:  # 如果键是D键
        #         print("D键被按下!")
    clock.tick(16)

    start_x%=96
    screen.blit(background, (0, 0))
    screen.blit(fum,(x,y),area=(start_x,0,24,32))
    # 如果事件类型为 KEYDOWN，即按下键盘按钮，则检查事件键
    # if event.type == pygame.KEYDOWN:
    #     pass
    # 如果按下的按钮是右箭头键，则增加 x 坐标
    keys_pressed = pygame.key.get_pressed()
    if keys_pressed[pygame.K_d]:
        # 如果右键被按下dd
        print("D key is pressed")
        x+=5
        start_x += 24
    else:start_x=0
    if keys_pressed[pygame.K_a]:
        # 如果右键被按下dd
        print("A key is pressed")
        #pygame.transform.flip(fum_rect, 1, 0)

    pygame.display.flip()



